package server;

/**
 * An Account is a persistent collection of data about a player.  Accounts are 
 * stored and maintained by the MasterServer.  When players connect to the MasterServer,
 * they must authenticate themselves by providing a username and password.  If they 
 * do not have an account, they can create one.  Account objects only exist on the
 * server while the players that own them are logged in; otherwise, they are serialized
 * to local storage.
 */
public class Account
{
	public Account(String username, String password) {
		this.username = username;
		this.password = password;
	}

	/**
	 * Returns the username associated with this account
	 */
	public String getUsername() {
		return username;
	}
	
	/**
	 * Returns the password associated with this account
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * Changes the password for this account.
	 * @param currentPassword the current password
	 * @param newPassword the new password
	 * @return true if the password change was successful; that is, if the old password
	 * was correct
	 */
	public boolean changePassword(String currentPassword, String newPassword)
	{
		if (currentPassword.equals(password)) 
		{
			password = newPassword;
			return true;
		}
		return false;
	}

	public String toString() {
		return username;
	}

	private final String username;
	private String password;
}